USB Device Passthrough (Redirect) to Hyper

您所在的位置:网站首页 hyper-v usb启动 USB Device Passthrough (Redirect) to Hyper

USB Device Passthrough (Redirect) to Hyper

2024-05-26 21:43| 来源: 网络整理| 查看: 265

One of the significant disadvantages of Hyper-V over other hypervisors (for example, VMWare ESXi or Proxmox) is the lack of a feature of redirecting USB devices from the host to virtual machines. Since version Hyper-V 2012 R2, there have been a number of changes regarding USB Passthrough options, but this functionality is still inferior to those of competitors. In this article, we will discuss the specifics of USB redirection in Hyper-V.

Contents:An Overview of Hyper-V USB PassthroughAccessing a USB Hard Drive from a Hyper-V Virtual MachineRedirect USB Device to VM with Hyper-V Enhanced Session ModeAn Overview of Hyper-V USB Passthrough

USB passthrough refers to the ability to redirect a USB device from the host hypervisor (or over the network from another server/device) to a virtual machine. Using a USB passthrough, you can redirect a USB stick, token, USB dongle, modem, or any other device connected to the physical host’s USB port to the virtual machine.

The bad news is that Hyper-V doesn’t support full-featured USB passthrough. You cannot redirect an arbitrary USB device from a physical host to a virtual machine (VMWare is much better with this – see the article USB passthrough in VMWare ESXi). There are several built-in options for using an external USB device in a Hyper-V VM, but they all have significant limitations. Currently, you can use the following ways to redirect a USB device to Hyper-V virtual machine.

Redirecting USB drives from Hyper-V host;Enhanced Session Mode on Hyper-V Console;USB Redirection via RDP;Using software/hardware solution for USB redirecting over the network (USB over IP). The last scenario involves the use of third-party solutions to implement USB over IP. It can be a network USB hub, a software solution to redirect a USB device over a TCP/IP network from another server. Most of the popular commercial solutions are paid (AnywhereUSB, DigiUSB). Free ones include VirtualHere USB (free for one USB dongle and one target server) and a rather old open source project usbip.sourceforge.net (the server part is implemented on Linux, the client can be installed on Windows).Accessing a USB Hard Drive from a Hyper-V Virtual Machine

You can fairly easily redirect a host-attached USB drive directly inside any running Hyper-V virtual machine. Let’s see how to give a Hyper-V virtual machine direct access to the host’s USB drive.

Note. This guide only works for USB drives that are detected by the system as fixed. You can’t redirect to VM this way USB flash drives, smart cards and other removable devices (although there is a little trick to make Windows see a removable device as a fixed hard drive).For these drives, you cannot create a snapshot/checkpoint.

Connect an external USB drive to the Hyper-V host (this can be any host with Windows and the Hyper-V role installed, or Free Microsoft Hyper-V Server). The drive will appear in a system and a drive letter will be assigned to it (if a drive letter has not been assigned, check the article);Open the Disk Management (diskmgmt.msc) console, right-click the drive (in our example, the ID of the 20 GB USB drive is Disk 1) and select Offline. disk management - set usb drive offline on hyper-v If you are using Windows Server Core or Hyper-V Server, which don’t have some of the graphical mmc snap-ins, you can manage your local disks using Disk Management PowerShell module. The following commands can list the physical disks on the host and take the specified disk offline: Get-Disk Get-Disk -Number 1 |Set-Disk -IsOffline:$true powershell set usb disk offlineRun Hyper-V Manager and open the properties of the virtual machine, to which a USB drive needs to be connected. In the SCSI Controller section, add a new disk, indicating that it is physical (Physical hard disk). In the drop-down menu select your USB drive (it will look something like this: Disk 1 20.00 Gb Bus 0 Lun 0 Target 1).Note. You don’t need to turn the virtual machine off to add a SCSI hard drive. For SCSI devices, hot-add and hot-remove drives are supported. Mount USB Drive into a VM from Hyper-V hostNow we will show how to access a USB disk on a Hyper-V host from the guest OS of a virtual machine running Windows. Open the virtual machine console or connect to it via RDP. Log in to the guest OS. Run the Disk Manager. The OS should see the new drive. If it is offline, right-click on it and select Online. At this time, no drive letters or mount points are assigned to partitions on a USB disk. To fix this, right-click on the partition on the disk and select “Change Drive Letter and Paths” from the context menu. Assign any free drive letter to the partition or specify a mount point.  disk management set drive letter

That’s all! You have directly connected external USB media into Hyper-V virtual machine and now can use it.

Important. To prevent data loss, before you physically remove the hard disk from USB port, make sure that no applications in the virtual machine access this disk.

To safely remove the USB drive, you can open the Hyper-V Manager console and go to the virtual machine settings window. In the SCSI Controller section, select the hard drive you want to remove and click Remove. Save your changes. After that, you can physically remove the hard drive from the USB port of the Hyper-V host.

Redirect USB Device to VM with Hyper-V Enhanced Session Mode

In the version of Hyper-V introduced in Windows Server 2012 R2/8.1, any USB device can be forwarded to a virtual machine from a client computer using Enhanced Session Mode (ESM). The Hyper-V Manager tool vmconnect.exe is used to connect. It allows you to connect to the virtual machine console and select the USB devices you want to redirect.

First you need to enable Enhanced Session Mode in the Hyper-V server settings. This can be done using PowerShell:

Set-VMHost -EnableEnhancedSessionMode $true

Or in the Hyper-V Settings -> Enhanced Session Mode.

enable Enhanced Session Mode on hyper-v host

Restart the Hyper-V Virtual Machine Management service: Get-Service vmms | Restart-Service

In the Integration Services section of the VM settings, you must enable the Guest Services option.

In order to redirect the USB device through Enhanced Session Mode, you need to open the Hyper-V console, select the virtual machine, and click the Connect button. Or you can run the vmconnect.exe tool (Virtual Machine Connection), specify the Hyper-V server and the virtual machine name. The vmconnect tool supports some command line options, so you can give a customized bat file with the options you want to users.

vmconnect.exe - connecting hyper-v virtual machine console

If the VM supports Enhanced Session Mode, a window similar to the RDP connection properties will appear. Click Show Option -> Local Resources -> Local device and resources -> More.

virtual machine connection - options

Select the USB devices on your computer to be redirected to the VM. If the device you want is not currently connected, select the “Other supported Plug and Play (PnP) devices” and “Devices that I plug in later options”.

Redirect USB Device To Hyper-V Virtual Machine via Console

Now all USB devices connected to your computer will be automatically available in the console session of the Hyper-V virtual machine.

Key features and limitations of Hyper-V Enhanced Session Mode:

Only Windows are supported as guest OS (starting from Windows 8.1 / Windows Server 2012 R2);You don’t need direct network access to the virtual machine. All connections are made through the Hyper-V host (you connect to it over the network via TCP port 2179), and the Hyper-V connects to the VM via the VMBus;Hyper-V Manager must be installed on the client’s computer.

This method is similar to redirecting USB devices from local host over an RDP session. We won’t consider this in more detail. Redirect USB via RDP

If you are redirecting USB devices over the network (USB over IP or over an RDP session), you can still access the USB key even after migrating the virtual machine to another host (Hyper-V Live Migration / VMware vMotion).



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3